<template>
  <div class="forum-detail-container">
    <m-header title="帖子内容"></m-header>
    <div class="post-detail">
      <div class="title">{{post.title}}</div>
      <div class="post-info">
        <div class="view">阅读{{post.read_num}}</div>
        <div class="reply">回复{{post.remark_num}}</div>
        <div class="next" @click="viewNext">查看下一篇
          <img src="../../../assets/imgs/forum/next.png" alt>
        </div>
      </div>
      <div class="user-info">
        <img class="avatar" :src="post.head_img">
        <div class="name-time">
          <div class="name">{{post.author}}</div>
          <div class="time">{{post.create_time | getDateDiff}}</div>
        </div>
      </div>
      <div class="content" v-html="post.content" />
    </div>
    <div class="divider" />
    <div class="cmt-detail">
      <div class="title">
        <div class="cmt-num"><span>评论</span>{{cmts.length}}</div>
        <div class="like-num"><span>已赞</span>{{post.like_num}}</div>
      </div>
      <div class="cmts">
        <div class="cmt" v-for="(item, index) in cmts" :key="index">
          <div class="avatar">
            <img :src="item.head_img" />
          </div>
          <div class="detail">
            <div class="name">
              {{item.nickname}}
            </div>
            <div class="content">
              {{item.content}}
            </div>
            <div class="time">
              {{item.create_time | getDateDiff}}
            </div>
          </div>
          <!-- <div class="like-btn">
            <img src="../../../assets/imgs/forum/appreciate_light@2x.png" alt ><span>{{item.like_num}}</span>
          </div> -->
        </div>
      </div>
    </div>
    <div class="send-cmt">
      <input v-model="cmt" placeholder="请说说你的看法" >
      <img src="../../../assets/imgs/forum/message_light@2x.png" alt @click="cmtPost">
      <img src="../../../assets/imgs/forum/appreciate_yellow@2x.png" alt @click="likePost">
    </div>
  </div>
</template>
<script>
import { mapActions } from 'vuex';
export default {
  data () {
    return {
      article_id: '',
      cmt: '',
      post: {},
      // post: {
      //   id: '1',
      //   title:
      //     '风暴来袭，放心跟踪，打造论坛最高无措记录，从此改变一生！',
      //   avatar: '',
      //   text: '据外媒报道，马来西亚王宫6日发布声明称，穆罕默德五世宣布辞去国家元首职务，具体原因未做说明。综合法新社、马来西亚《星报》消息，当地时间6日，马来西亚王宫事务主管万·艾哈迈德发布声明表示，穆罕默德五世按联邦宪法第32（3）条辞去第15任国家元首的职务，声明于1月6日生效。这是马来西亚首位在任内宣布辞职的国家元首。<br />据外媒报道，马来西亚王宫6日发布声明称，穆罕默德五世宣布辞去国家元首职务，具体原因未做说明。综合法新社、马来西亚《星报》消息，当地时间6日，马来西亚王宫事务主管万·艾哈迈德发布声明表示，穆罕默德五世按联邦宪法第32（3）条辞去第15任国家元首的职务，声明于1月6日生效。这是马来西亚首位在任内宣布辞职的国家元首。',
      //   name: '篮球王',
      //   view: '2万',
      //   time: '1小时前',
      //   nextId: '2'
      // },
      cmts: []
      //  {
      //   num: 268,
      //   like: 563,
      //   list: [{
      //     avatar: '',
      //     name: '据外媒报道',
      //     desc: '马来西亚王宫6日发布声明称，穆罕默德五世宣布辞去国家元首职务',
      //     time: '2分钟前'
      //   }, {
      //     avatar: '',
      //     name: '据外媒报道',
      //     desc: '马来西亚王宫6日发布声明称，穆罕默德五世宣布辞去国家元首职务',
      //     time: '2分钟前'
      //   }]
      // }
    };
  },
  mounted () {
    const {id: article_id} = this.$router.history.current.params || {};
    this.article_id = article_id;
    this.getDetail();
    // this.getCmts();
  },
  methods: {
    ...mapActions({
      getPostDetail: 'forum/getPostDetail',
      getArticleRemark: 'forum/getArticleRemark',
      remarkArticle: 'forum/remarkArticle',
      likeArticle: 'forum/likeArticle'
    }),
    getDetail () {
      this.getPostDetail({article_id: this.article_id}).then(res => {
        if (res) {
          this.post = res;
          this.getCmts();
        }
      });
    },
    getCmts () {
      this.getArticleRemark({article_id: this.article_id}).then(res => {
        if (res) {
          this.cmts = res;
        }
      });
    },
    cmtPost () {
      this.remarkArticle({article_id: this.article_id, content: this.cmt}).then(res => {
        if (res) {
          this.cmt = '';
          this.getCmts();
        }
      });
    },
    likePost () {
      this.likeArticle({article_id: this.article_id}).then(res => {
        if (res) {
          this.post.like_num = Number(this.post.like_num) + 1;
          // this.getCmts();
        }
      });
    },
    viewNext () {
      this.article_id = Number(this.article_id) + 1;
      this.getDetail();
      // this.getCmts();
    }
  }
};
</script>
<style lang="less" scoped>
.forum-detail-container {
  margin-top: 0.92rem;
  background: #ffffff;
  height: 100%;
  .avatar {
    border-radius: 50%;
  }
  .post-detail {
    background: #ffffff;
    padding: 0.3rem 0.2rem;
    .title {
      font-size: 0.34rem;
      color: #333333;
      line-height: 0.48rem;
    }
    .post-info {
      padding-top: 0.2rem;
      padding-bottom: 0.3rem;
      border-bottom: 1px solid #d2d2d2;
      font-size: 0.22rem;
      color: #999999;
      .view {
        display: inline-block;
        margin-right: 0.2rem;
      }
      .reply {
        display: inline-block;
      }
      .next {
        // display: inline-block;
        display: flex;
        align-items: center;
        float: right;
        img {
          // transform: rotate(180deg);
          margin-left: 0.1rem;
          width: 0.18rem;
          height: 0.3rem;

        }
      }
    }
    .user-info {
      padding: 0.3rem 0;
      .avatar {
        width: 0.72rem;
        height: 0.72rem;
        margin-right: 0.2rem;
        vertical-align: baseline;
      }
      .name-time {
        display: inline-block;
      }
      .name {
        padding-bottom: 0.2rem;
      }
      .time {
        font-size: 0.22rem;
        color: #999999;
      }
    }
  }
  .divider {
    height: 0.2rem;
    background: #f6f6f6;
  }
  .cmt-detail{
    // margin-top: 0.2rem;
    padding-bottom: 0.68rem;
    background: white;
    .title {
      height: 0.8rem;
      line-height: 0.8rem;
      font-size: 0.26rem;
      color: #666666;
      padding-left: 0.2rem;
      .cmt-num {
        display: inline-block;
        width: 5.9rem;
        span {
          margin-right: 0.1rem;
        }
      }
      .like-num{
        display: inline-block;
        span {
          margin-right: 0.1rem;
        }
      }
    }
    .cmts{
      border-top: 1px solid #d2d2d2;
      border-bottom: 1px solid #d2d2d2;
      .cmt {
        position: relative;
        display: flex;
        padding: 0.2rem;
        .avatar{
          width: 0.72rem;
          margin-right: 0.2rem;
          img{
            width: 0.72rem;
            height: 0.72rem;
          }
        }
        .detail{
          .name{
            font-size: 0.26rem;
            color: #666666;
          }
          .content{
            font-size: 0.3rem;
            color: #333333;
            margin-top: 0.3rem;
            margin-bottom: 0.3rem;
          }
          .time{
            font-size: 0.22rem;
            color: #999999;
          }
        }
        .like-btn {
          position: absolute;
          bottom: 0.2rem;
          right: 0;
          img {
            display: inline-block;
            width: 0.3rem;
            height: 0.3rem;
            margin-right: 0.2rem;
          }
          span {
            width: 0.6rem;
            display: inline-block;
            font-size: 0.22rem;
            color: #333333;
          }
        }
      }
    }
  }
  .send-cmt {
    position: fixed;
    bottom: 0;
    height: 1.28rem;
    line-height: 1.28rem;
    background: #ffffff;
    left: 0;
    right: 0;
    padding-left: 0.2rem;
    border-top: 1px solid #d2d2d2;
    input {
      width: 5.3rem;
      background: #f2f2f2;
      border-radius: 0.34rem;
      height: 0.68rem;
      padding-left: 0.3rem;
      &::-webkit-input-placeholder {
        color: #999999;
        font-size: 0.22rem;
      }
    }
    img {
      margin-left: 0.2rem;
      width: 0.4rem;
      height: 0.4rem;
    }
  }
}
</style>
